﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight.Messaging;
using Bymed.SpineScan.DataModel;
using Bymed.SpineScan.WPF.Shared;
using Bymed.SpineScan.WPF.ViewModel;

namespace Bymed.SpineScan.WPF
{
    /// <summary>
    /// Interaction logic for PatientBasicInfoPage.xaml
    /// </summary>
    public partial class PatientBasicInfoPage : PageBase
    {
        public PatientBasicInfoPage()
        {
            InitializeComponent();
            InitializePageUnloadStoryboard();
        }

        protected override void RegisterMessages()
        {
            base.RegisterMessages();

            RegisterGoToNextPageMessage();
            RegisterChangeDataConfirmMessage();
        }

        /// <summary>
        /// Register the GoToNextPageMessage from PatientBasicInfoViewModel.
        /// </summary>
        private void RegisterGoToNextPageMessage()
        {
            Messenger.Default.Register<PatientBasicInfoDisplayViewModel>(this, PatientBasicInfoViewModel.GoToNextPageMessageToken, patient =>
            {
                try
                {
                    var selectTestItemPage = new SelectTestItemPage();
                    var selectTestItemViewModel = selectTestItemPage.DataContext as SelectTestItemViewModel;
                    selectTestItemViewModel.PatientBasicInfoDisplayViewModel = patient;

                    GoToPage(selectTestItemPage);
                }
                catch (Exception ex)
                {
                    MyViewModelBase.RequestDisplayErrorMessage(ex.Message);
                }
            });
        }

        /// <summary>
        /// Register the ChangeDataConfirmMessage from PatientBasicInfoViewModel.
        /// </summary>
        private void RegisterChangeDataConfirmMessage()
        {
            Messenger.Default.Register<DialogMessage>(this, PatientBasicInfoViewModel.ChangeDataConfirmMessageToken, dialog =>
            {
                var confirmResult = MessageBox.Show(dialog.Content, dialog.Caption, dialog.Button, dialog.Icon);
                dialog.ProcessCallback(confirmResult);
            });
        }

        private void ButtonSearch_Click(object sender, RoutedEventArgs e)
        {
            GoToPage(new PatientDataSearchPage());
        }
    }
}
